﻿using MediatR;
using System.CJL.API.Application.Command.FinishedProductsCommand;
using System.CJL.Domain;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.FinishedProductsCommandHanler
{
	/// <summary>
	/// 修改
	/// </summary>
	public class FinishedProductsUpdateCommandHandler:IRequestHandler<FinishedProductsUpdateCommand,int>
	{
		IFinishedProductRepositry _repository;
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="repository"></param>
        public FinishedProductsUpdateCommandHandler(IFinishedProductRepositry repository)
        {
			_repository=repository;

		}
		/// <summary>
		/// 修改
		/// </summary>
		/// <param name="request"></param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>
		public async Task<int> Handle(FinishedProductsUpdateCommand request, CancellationToken cancellationToken)
		{
			return await _repository.UpdateAsync(new Domain.FinishedProduct
			{
				finishedProductId=request.finishedProductId,
				finishedProductNumbering = request.finishedProductNumbering,
				finishedProductName = request.finishedProductName,
				finishedProductModel = request.finishedProductModel,
				finishedProductUnit = request.finishedProductUnit,
				finishedProductUpperLimit = request.finishedProductUpperLimit,
				finishedProductDays = request.finishedProductDays,
				finishedProductBatch = request.finishedProductBatch,
				finishedProductLowerLimit = request.finishedProductLowerLimit,
				finishedProductState = request.finishedProductState,
				finishedProductRemark = request.finishedProductRemark,
				finishedProductImg = request.finishedProductImg,
				AddName = request.AddName,
				AddTime = request.AddTime,
				UpdateName = request.UpdateName,
				UpdateTime = DateTime.Now.ToUniversalTime(),
			});
		}
	}
}
